﻿//window.onload = function () {
//    alert("aa");
//    Silverlight.createObjectEx({
//        source: "ClientBin/DOE.GIS.A11.xap",
//        parentElement: silverlightControlHost,
//        id: "sl4",
//        properties: {
//            width: "80%",
//            height: "80%",
//            background: "white",
//            alt: "<!--not installed-->",
//            version: "4.0.50826.0"
//        },
//        events: {
//            onError: onSilverlightError,
//            onLoad: pluginLoaded
//        },
//        initParams: "splashscreensource=http://10.65.247.231/A4SysInt/Scripts/Scene.xaml ,OnSourceDownloadProgressChanged=onProgressChanged,initparams=DefaultMapConfig=http://localhost:8668/Configs/A11.xml,IsDebug=true",
//        //context: "row4"
//    });
//}
var slCtl = null;
//初始化方法
function pluginLoaded(sender) {
    //slCtl = sender.getHost();
    slCtl = document.getElementById("sl4");
    //            alert(slCtl.Content.mymapwrap.ShowError("test string"));
    //            slCtl.Content.mymapwrap.LayerFilter("企业信息", "VLD_ENTERPRISE_ID=10001");
    //            slCtl.Content.mymapwrap.LayerListControl("企业信息");
    //            slCtl.Content.mymapwrap.ZoomToFeature("PIPETEST.ZY4_ENV_DANGER_SOURCE_2", "ENV_ID=179");
    //            slCtl.Content.mymapwrap.DrawPoint("116.3,39.9", "", 6, 6);
    //            slCtl.Content.mymapwrap.ZoomToPoint("116.3,39.9", 6);
}
function displayDIV() {
    if ($("#div").css("display") == null) {
        $("#div").show();
    } else {
        //var aa=$("#div").children[0].value;
        $("#div").css("z-index", "1");
    }
}
//地图左键单击事件
function OnMapLeftButtonUp() {
    //alert("OnMapLeftButtonUp");
}
//图标左键点击up事件
function VectorLeftButtonUp(ENV_ID, tablename, MouseLocation) {
    //alert("表名：" + tablename + "；唯一标示：" + ENV_ID + "；位置：" + MouseLocation);
    
    //var strs = new Array();
    //strs = slCtl.Content.mymapwrap.CenterPoint.split(',');
    ZoomToFeature("CSSDE.MK_PETROL_STATION", "LA23");
    sendMessage("COMMAND CommandName:GisLocation;Lon:0;Lat:0;ZoomLevel:0;ID:'" + tablename + "|" + ENV_ID+"'"); //COMMAND 控制命令


    //sendMessage("COMMAND " + GetCenterPointLevel());
    //return "fdf";
}
//图标左键点击Down事件
function VectorLeftButtonDown(ENV_ID, tablename, MouseLocation) {
    //alert("表名：" + tablename + "；唯一标示：" + ENV_ID + "；位置：" + MouseLocation);
    //return "fdf";
}



//图标右键点击事件
function VectorRightButtonUp(ENV_ID, tablename, MouseLocation) {
    alert("表名：" + tablename + "；唯一标示：" + ENV_ID + "；位置：" + MouseLocation);
    //return html;
}

function VectorMouseLeave(ENV_ID, tablename, MouseLocation) {
    //alert("表名：" + tablename + "；唯一标示：" + ENV_ID + "；位置：" + MouseLocation);
    //return html;
}

//鼠标移入事件
function VectorMouseEnter(ENV_ID, tablename) {
   // alert(tablename + ENV_ID);
    return "fdf";
}
//图层控制接口
function LayerListControl() {
    slCtl.Content.mymapwrap.LayerListControl("环境应急监测站信息,原油管道");
}

//图层过滤接口
function LayerFilter() {
    slCtl.Content.mymapwrap.LayerFilter("企业信息", "VLD_ENTERPRISE_ID=10001");
}
//定位对象接口
function ZoomToFeature(tableName,env_ID) {
    //slCtl.Content.mymapwrap.ZoomToFeature("PIPETEST.ZY4_ENV_DANGER_SOURCE_2", "extendcode='lol0'");
    slCtl.Content.mymapwrap.ZoomToFeature(tableName, "extendcode='"+env_ID+"'");
}
//定位经纬度坐标接口
function ZoomToPoint(center,level) {
    slCtl.Content.mymapwrap.ZoomToPoint(center, level);
}

//更改图标接口
//function ChangeFeaturePic() {
//    slCtl.Content.mymapwrap.ChangeFeaturePic("PIPETEST.ZY4_ENV_EMER_MONITOR_2", "OBJECTID", "2", "feiji");
//}


function ChangeFeaturePic(va1, va2, va3, va4) {
    slCtl.Content.mymapwrap.ChangeFeaturePic(va1, va2, va3, va4);
}

//获取当前视野范围内的数据
function GetEyeMapData(listData) {

    var sl = document.getElementById("sl4").content;
    //var listData=slCtl.Content.mymapwrap.GetEyeMapData();
    alert(listData);
}
//获取中心点坐标和显示级别
function GetCenterPointLevel() {
    var center = slCtl.Content.mymapwrap.CenterPoint;
    var level = slCtl.Content.mymapwrap.Level;
    var canterLevel = slCtl.Content.mymapwrap.GetCenterPointLevel();
    return canterLevel;
    //alert(canterLevel);

}

var s=0;
var ints = self.setInterval(function () {
    if (s == 0)
    { s = 1; }
    if (s == 1)
    { s = 0;}
}, 50);
//视野变化事件接口
function OnMapViewChangedEnd(sender, args) {
    if (s == 0) {
        var strs = new Array();
        strs=slCtl.Content.mymapwrap.CenterPoint.split(',');
        sendMessage("COMMAND CommandName:GisLocation;Lon:" + strs[0] + ";Lat:" + strs[1] + ";ZoomLevel:" + slCtl.Content.mymapwrap.Level + ";ID:" + 0); //COMMAND 控制命令
        //sendMessage("COMMAND " + "GIS:"+slCtl.Content.mymapwrap.CenterPoint + "," + slCtl.Content.mymapwrap.Level);
    }
    //alert(sender+";"+args);
}
//画点接口
function DrawPoint() {
    slCtl.Content.mymapwrap.DrawPoint("116.3,39.9", "", 6, 6);
}
function onSilverlightError(sender, args) {
    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }

    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError") {
        return;
    }

    var errMsg = "Silverlight 应用程序中未处理的错误 " + appSource + "\n";

    errMsg += "代码: " + iErrorCode + "    \n";
    errMsg += "类别: " + errorType + "       \n";
    errMsg += "消息: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "文件: " + args.xamlFile + "     \n";
        errMsg += "行: " + args.lineNumber + "     \n";
        errMsg += "位置: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "行: " + args.lineNumber + "     \n";
            errMsg += "位置: " + args.charPosition + "     \n";
        }
        errMsg += "方法名称: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}